package com.example.petcare.mapper;

import com.example.petcare.pojo.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetMapper {

    // 新增宠物
    @Insert("insert into pet(user_id,pet_name, pet_type, pet_age, pet_gender, pet_weight,pet_pic) values (#{userId},#{petName}, #{petType}, #{petAge}, #{petGender}, #{petWeight},#{petPic})")
    void addPet(Pet pet);

    // 删除宠物
    @Delete("delete from pet where pet_id = #{petId}")
    void deletePet(Integer petId);

    // 修改宠物
    @Update("update pet set pet_name=#{petName}, pet_type=#{petType}, pet_age=#{petAge}, pet_gender=#{petGender}, pet_weight=#{petWeight},pet_pic=#{petPic} where pet_id=#{petId}")
    void updatePet(Pet pet);

    // 获取宠物详情
    @Select("select * from pet where pet_id = #{petId}")
    Pet findById(Integer petId);

    // 获取用户宠物列表
    @Select("select * from pet where user_id = #{userId}")
    List<Pet> list(Integer userId);
}
